package controller

import (
	"exam_go/service"
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

type AdminController struct {
}

func (u AdminController) AddItems(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.AddItemsservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
func (u AdminController) AddService(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.AddServiceservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
func (u AdminController) AddServiceTime(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.AddServiceTimeservice(c)
	if err != nil {
		fmt.Printf("controller error: %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
func (u AdminController) UpdateServiceTimeAvailability(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.UpdateServiceTimeAvailability(c)
	if err != nil {
		fmt.Printf("controller error: %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) DeleteGoods(c *gin.Context) {
	AdminService := service.AdminService{}
	err := AdminService.DeleteGoodsservice(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	print("1111")
	c.JSON(http.StatusOK, gin.H{
		"success": true,
	})
}

func (u AdminController) EditItem(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.EditItemservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) EditService(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.EditServiceservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
func (u AdminController) QueryUser(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.QueryUserservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetItemTimeRange(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetItemTimeRangeService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"code":    0,
		"data":    resp,
	})
}

func (u AdminController) HandleGetServiceTimeRange(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetServiceTimeRangeService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetTotalRevenue(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetTotalRevenueService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetTotalOrders(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetTotalOrdersService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetTotalUsers(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetTotalUsersService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetTotalRefunds(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetTotalRefundsService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) HandleGetSoldQuantity(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetSoldQuantityService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

// 查询物品状态
func (u AdminController) GetItemStatus(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetItemStatus(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	print("111")
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetServiceInfo(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetServiceInfo(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	print("111")
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetOrderInfo(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetOrderInfo(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	print("111")
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetAllInfoByID(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetAllInfoByID(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, resp)
}

func (u AdminController) GetAllItem(c *gin.Context) {
	AdminService := service.AdminService{}

	resp, err := AdminService.GetAllItem(c)

	print("123")

	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetAllService(c *gin.Context) {
	AdminController := service.AdminService{}

	resp, err := AdminController.GetAllService(c)

	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	print("111")
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetAllInfoByName(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetAllInfoByName(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) GetTotalReport(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetTotalReport(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) EditUsers(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.EditUsers(c)
	print("222")
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
func (u AdminController) GetGoods(c *gin.Context) {
	AdminService := service.AdminService{}
	resp, err := AdminService.GetGoods(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u AdminController) EditOrder(c *gin.Context) {
	AdminService := service.AdminService{}
	err := AdminService.EditOrder(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
	})
}
